package com.sailorj.controller;

import com.sailorj.entity.TbEnlist;
import com.sailorj.service.TbEnlistService;
import com.sailorj.util.PageBean;
import com.sailorj.util.SysLoging;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: springLab
 * @description:
 * @author: huangshengjun
 * @create: 2020-04-19 16:07
 **/
@CrossOrigin  //后端解决跨域方法注解
@Controller
@RequestMapping("/enlist") //访问的路径
public class TbEnlistController {

    private static final Logger logger = LoggerFactory.getLogger(SysUserController.class);
    @Autowired
    private TbEnlistService tbEnlistService;


    /**
     * restful风格实现
     * @return
     */
    @ResponseBody
    @SysLoging("添加报名信息") //根据SysLoging的注解信息，进行方法的注释
    @RequestMapping(value = "/addEnlist",method = RequestMethod.POST) //restful风格
    public String addEnlist(TbEnlist Enlist){
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Enlist.setCreatTime(formatter.format(date));
        Enlist.setState("0");//是否录取，0待操作，1同意。2不同意
        tbEnlistService.addEnlist(Enlist);
        return "";
    }


    @ResponseBody
    @SysLoging("根据id查询报名信息")
    @RequestMapping(value = "/getEnlistById",method = RequestMethod.GET)
    public TbEnlist getEnlistById(int id){
        return tbEnlistService.getEnlistById(id);
    }

    @ResponseBody
    @SysLoging("获取报名信息列表")
    @RequestMapping(value = "/getEnlistList",method = RequestMethod.GET)
    PageBean getEnlistList(@RequestParam(defaultValue = "1") Integer page,
                        @RequestParam(defaultValue = "10") Integer size){
        return tbEnlistService.getEnlistList(page,size);
    }

    @ResponseBody
    @SysLoging("删除报名信息")
    @RequestMapping(value = "/deleteEnlist",method = RequestMethod.DELETE)
    public String deleteEnlist(int id) {
//        tbEnlistService.deleteByPrimaryKey(id);
        return "";
    }

    @ResponseBody
    @SysLoging("更新报名信息")
    @RequestMapping(value = "/updateEnlist",method = RequestMethod.PUT)
    public String updateEnlist(TbEnlist Enlist) {
        tbEnlistService.updateEnlistById(Enlist);
        return "";
    }

    @ResponseBody
    @SysLoging("通过学生申请信息")
    @RequestMapping(value = "/edit1",method = RequestMethod.PUT)
    public String edit1(int id) {
        TbEnlist tbEnlist = new TbEnlist();
        TbEnlist tbEnlist1 = tbEnlistService.getEnlistById(id);
        tbEnlist.setId(tbEnlist1.getId());
        tbEnlist.setPlanId(tbEnlist1.getPlanId());
        tbEnlist.setPlanName(tbEnlist1.getPlanName());
        tbEnlist.setTbDescribe(tbEnlist1.getTbDescribe());
        tbEnlist.setStudentName(tbEnlist1.getStudentName());
        tbEnlist.setCreatTime(tbEnlist1.getCreatTime());
        tbEnlist.setState("1");//是否录取，0待操作，1同意。2不同意
        tbEnlistService.updateEnlistById(tbEnlist);
        logger.info(tbEnlist.toString());
        return "";
    }

    @ResponseBody
    @SysLoging("拒绝学生申请信息")
    @RequestMapping(value = "/edit2",method = RequestMethod.PUT)
    public String edit2(int id) {
        TbEnlist tbEnlist = new TbEnlist();
        TbEnlist tbEnlist1 = tbEnlistService.getEnlistById(id);
        tbEnlist.setId(tbEnlist1.getId());
        tbEnlist.setPlanId(tbEnlist1.getPlanId());
        tbEnlist.setPlanName(tbEnlist1.getPlanName());
        tbEnlist.setTbDescribe(tbEnlist1.getTbDescribe());
        tbEnlist.setStudentName(tbEnlist1.getStudentName());
        tbEnlist.setCreatTime(tbEnlist1.getCreatTime());
        tbEnlist.setState("2");//是否录取，0待操作，1同意。2不同意
        tbEnlistService.updateEnlistById(tbEnlist);
        logger.info(tbEnlist.toString());
        return "";
    }

    @ResponseBody
    @SysLoging("数据更改申请信息")
    @RequestMapping(value = "/edit3",method = RequestMethod.PUT)
    public String edit3(int id) {
        TbEnlist tbEnlist = new TbEnlist();
        TbEnlist tbEnlist1 = tbEnlistService.getEnlistById(id);
        tbEnlist.setId(tbEnlist1.getId());
        tbEnlist.setPlanId(tbEnlist1.getPlanId());
        tbEnlist.setPlanName(tbEnlist1.getPlanName());
        tbEnlist.setTbDescribe(tbEnlist1.getTbDescribe());
        tbEnlist.setStudentName(tbEnlist1.getStudentName());
        tbEnlist.setCreatTime(tbEnlist1.getCreatTime());
        tbEnlist.setState("2");//是否录取，0待操作，1同意。2不同意
        tbEnlistService.updateEnlistById(tbEnlist);
        logger.info(tbEnlist.toString());
        return "";
    }
}
